package com.init.iblog.Controller;


import com.init.iblog.domain.ResponseResult;
import com.init.iblog.domain.entity.Menu;
import com.init.iblog.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 查询菜单列表
     * @param status
     * @param menuName
     * @return
     */
    @GetMapping("/list")
    public ResponseResult getMenuList(String status ,String menuName){
        return menuService.getMenuList(status,menuName);
    }

    /**
     * 新增菜单
     * @param menu
     * @return
     */
    @PostMapping
    public ResponseResult addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }

    /**
     * 根据id查询菜单数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getMenuInfo(@PathVariable Long id){
        return menuService.getMenuInfo(id);
    }

    /**
     * 修改菜单信息
     * @param menu
     * @return
     */
    @PutMapping
    public ResponseResult editMenu(@RequestBody Menu menu){
        return menuService.editMenu(menu);
    }


    /**
     * 删除菜单
     * 当该菜单有子菜单时，不允许删除
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    public ResponseResult deleteMenu(@PathVariable Long menuId){
        return menuService.deleteMenu(menuId);
    }

    /**
     * 查询下拉菜单的树形结构
     * @return
     */
    @GetMapping("/treeselect")
    public ResponseResult treeselect(){
        System.out.println("==============查询下拉菜单的树形结构=========");
        return menuService.treeselect();
    }

    /**
     * 根据角色id查询菜单下拉树形结构
     * @param id
     * @return
     */
    @GetMapping("/roleMenuTreeselect/{id}")
    public ResponseResult roleMenuTreeselect(@PathVariable Long id){
        System.out.println("===========根据角色id查询菜单下拉树形结构===========");
        return menuService.roleMenuTreeselect(id);
    }

}
